--[[ 编码: WMS-20-29 名称: 点领用按钮后 作者:HAN 日期:2025-1-29 级别:项目 函数: ClickReceiveButton 功能: -- 点击领用按钮 更改记录: V3.0 HAN 20241231 改成后台线程来处理空料箱呼出计算,因为这个过程是一个比较长的事务,有并发锁表的风险 本次改进的目的就是将这些长事务统一交给后台一个线程排队处理 V4.0 HAN 20250312 对选中的入库单进行检查如果已经有入库波次的不进行领用 --]] wms_base = require ("wms_base") function ClickReceiveButton ( strLuaDEID ) local nRet, strRetInfo, n local data_json nRet, data_json = m3.GetSysDataJson( strLuaDEID ) if (nRet ~= 0) then lua.Error( strLuaDEID, debug.getinfo(1), data_json ) end local nCount = #data_json if ( nCount == 0 ) then mobox.setInfo( strLuaDEID, "必须选中一个入库单!" ) return end --V4.0 HAN 2025/3/12 local inbound_obj local checked_data_json = {} local msg = '' for n = 1, nCount do -- 获取出库单对象 nRet, inbound_obj = m3.GetDataObject( strLuaDEID, "Inbound_Order", data_json[n].id ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), inbound_obj ) end -- 如果选择的出库单已经有出库波次号 if ( inbound_obj.wave_no ~= '' or inbound_obj.b_state ~= 0 ) then msg = msg.."\r\n单号='"..inbound_obj.no.."'的入库单已经有入库波次!" else table.insert( checked_data_json, data_json[n] ) end end if ( #checked_data_json == 0 ) then mobox.setInfo( strLuaDEID, msg ) return end -- 获取输入界面中的工作台属性 nRet, strRetInfo = mobox.getCurEditDataObjAttr( strLuaDEID, "Station" ) local input_value = json.decode( strRetInfo ) local station = lua.Get_StrAttrValue( input_value[1].value ) if ( station == '' ) then mobox.setInfo( strLuaDEID, "必须选择一个工作站!" ) return end local strUserLogin, strUserName nRet, strUserLogin, strUserName = mobox.getCurUserInfo( strLuaDEID ) if ( nRet ~= 0 ) then mobox.setInfo( strLuaDEID, "获取当前操作人员信息失败! "..strUserLogin ) return end -- V4.0 -- 如果有选中的入库单不符合要求,前端显示一下 if ( msg ~= '' ) then mobox.setInfo( strLuaDEID, msg ) end -- 组织后台脚本执行的输入参数 local paramter = { station = station, login = strUserLogin, user_name = strUserName, data_json = checked_data_json } nRet, strRetInfo = mobox.addBackendScriptProc( "Inbound_Order","入库空料箱计算", lua.table2str( paramter ) ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), strRetInfo ) end local data_json = {proc_id = strRetInfo} local action = { { action_type = "wait", value = { time = 1, event = { cls_name = "入库单", event_name = "获取入库空料箱计算结果", data_json = data_json } } }, } nRet, strRetInfo = mobox.setAction( strLuaDEID, lua.table2str(action) ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "setAction失败! "..strRetInfo..' action = '..strAction ) end end